package com.soap.desensitize.encry.irreversible;


import com.soap.desensitize.encry.IDesensitization;
import com.soap.desensitize.exception.strategy.DecodeException;

/**
 * @desc 	不可逆加密抽象基类
 * @author 	高增源
 * @time	2022-04-20
 */
public abstract class AbstractIRreversibleEncry<T> implements IDesensitization<T> {
	
	/**
	 * @desc 16进制字符数组
	 */
	protected char[] hex = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
	
	/**
     * 将字节数组转换成十六进制字符串
     * @param bytes
     * @return
     */
    protected String byte2str(byte []bytes){
        int len = bytes.length;   
        StringBuffer result = new StringBuffer();    
        for (int i = 0; i < len; i++) {   
            byte byte0 = bytes[i];   
            result.append(hex[byte0 >>> 4 & 0xf]);   
            result.append(hex[byte0 & 0xf]);   
        }
        return result.toString();
    }

    @Override
    public T decode(T data) throws DecodeException {
        throw new DecodeException("该加密策略无法解密，请使用 com.rj.bd.strategy.rreversible 包下的加密策略");
    }
}
